package hedron.dialog;

import static hedron.i18n.Internationalization._;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class AboutDialog extends AbstractDialog {

	public AboutDialog(Shell parentShell) {
		super(parentShell);
	}

	@Override
	public void create() {
		super.create();
		setTitle(_("Dialog.About.Title"));
		setMessage(_("Dialog.About.Message"), 0);
	}

	@Override
	void createContent(Composite parent) {

		Composite grid = new Composite(parent, 0);
		grid.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

		{// set parent layout
			GridLayout layout = new GridLayout();
			layout.numColumns = 1;
			grid.setLayout(layout);
		}
		{
			GridData gdata = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
			gdata.widthHint = 360;
			grid.setLayoutData(gdata);
		}
		{// cell 1 - search text
			Label label = new Label(grid, 0);
			GridData gdata = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
			label.setLayoutData(gdata);
			label.setText(_("Dialog.About.Text"));
		}
	}

	@Override
	void createFooter(Composite parent) {
		((GridLayout) parent.getLayout()).numColumns = 1;
		Composite grid = new Composite(parent, 0);
		grid.setLayoutData(new GridData(GridData.FILL, GridData.END, true, false));

		{// set grid layout
			GridLayout layout = new GridLayout();
			layout.numColumns = 2;
			grid.setLayout(layout);
		}
		{// cell 1 - empty text
			Label label = new Label(grid, 0);
			label.setText("");
			GridData gdata = new GridData(GridData.FILL, GridData.END, true, false);
			gdata.heightHint = 20;
			label.setLayoutData(gdata);
			label.setFocus();
		}
		{// ok
			Button button = new Button(grid, SWT.PUSH);
			button.setText("OK");
			GridData gdata = new GridData(GridData.END, GridData.END, false, false);
			gdata.heightHint = 20;
			gdata.widthHint = 100;
			button.setLayoutData(gdata);
			button.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent event) {
					setReturnCode(OK);
					close();
				}
			});

			// set button as default
			Shell shell = grid.getShell();
			if (shell != null) {
				shell.setDefaultButton(button);
			}
		}
	}
}
